package cn.vehicle.controller;

import cn.vehicle.biz.SysPermissionBiz;
import cn.vehicle.domains.vo.BasePage;
import cn.vehicle.domains.vo.Result;
import cn.vehicle.domains.vo.req.sysPermission.AddPermissionReq;
import cn.vehicle.domains.vo.req.sysPermission.PermissionListReq;
import cn.vehicle.domains.vo.req.sysPermission.UpdatePermissionReq;
import cn.vehicle.domains.vo.res.sysPermission.SysPermissionRes;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/permission") // 与用户、角色接口路径规范一致，前缀为/api/permission
@Slf4j
@Tag(name = "SysPermissionController", description = "权限管理相关接口")
public class SysPermissionController {

    @Resource
    private SysPermissionBiz sysPermissionBiz;

    @PostMapping("/add")
    @Operation(description = "创建权限接口")
    public Result<Void> addPermission(@RequestBody @Valid AddPermissionReq req) {
        sysPermissionBiz.addPermission(req);
        return Result.success();
    }

    @PostMapping("/updatePermission")
    @Operation(description = "更新权限接口")
    public Result<Void> updatePermission(@RequestBody @Valid UpdatePermissionReq req) {
        sysPermissionBiz.updatePermission(req);
        return Result.success();
    }

    @PostMapping("/deletePermission")
    @Operation(description = "删除权限接口")
    public Result<Void> deletePermission(
            @Parameter(schema = @Schema(name = "id", description = "权限ID"))
            @RequestParam Long id) {
        sysPermissionBiz.deletePermission(id);
        return Result.success();
    }

    @PostMapping("/getPermissionById")
    @Operation(description = "查询权限详情接口")
    public Result<SysPermissionRes> getPermissionById(
            @Parameter(schema = @Schema(name = "id", description = "权限ID"))
            @RequestParam Long id) {
        return Result.success(sysPermissionBiz.getPermissionById(id));
    }

    @PostMapping("/list")
    @Operation(description = "分页查询权限列表接口")
    public Result<BasePage<SysPermissionRes>> list(@RequestBody @Valid PermissionListReq req) {
        return Result.success(sysPermissionBiz.list(req));
    }



}
